package com.burstly.lib.component.networkcomponent.burstly;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import com.burstly.lib.component.AdaptorCustomFullscreen;
import com.burstly.lib.component.IBurstlyAdaptor.BurstlyAdType;
import com.burstly.lib.component.IBurstlyAdaptorListener;
import com.burstly.lib.component.IBurstlyAdaptorListener.FullscreenInfo;
import com.burstly.lib.component.LayoutParametersResolver;
import com.burstly.lib.component.networkcomponent.ClickAwareWrapper;
import com.burstly.lib.network.beans.ResponseBean.ResponseData;
import com.burstly.lib.network.beans.ResponseBean.ResponseData.AdType;
import com.burstly.lib.network.request.DefaultRequestCallback;
import com.burstly.lib.network.request.ImageFetchTask;
import com.burstly.lib.service.SdCardWatchingService;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.Map;

public final class BurstlyImageAdaptor extends AbstractBurstlyAdaptor
  implements OverlayContainer.IOverlayListener
{
  private static final IBurstlyAdaptorListener.FullscreenInfo FULLSCREEN_INFO = new IBurstlyAdaptorListener.FullscreenInfo("burstlyImage", true);
  static final String NETWORK_NAME = "burstlyImage";
  private static final int TRANSPARENT_INTERSTITIAL_EXTENDED_PROPERTY_FLAG = 4096;
  static BurstlyImageAdaptor sImageAdaptor;
  ImageView mImage;
  private String mImageUrl;
  private Integer mInterstitialShowtime;
  View mInterstitialView;
  boolean mIsInterstitial;
  private boolean mIsTransparentBg;
  private ImageFetchTask mLoadImageTask;

  BurstlyImageAdaptor(Context paramContext, String paramString)
  {
    super(paramContext, paramString);
    this.mTag = (paramString + " BurstlyImageAdaptor");
    SdCardWatchingService.startWatching(paramContext);
    ImageCache.initCache(paramContext);
  }

  private void downloadImage(boolean paramBoolean)
  {
    ImageCallback localImageCallback = new ImageCallback(this, null);
    localImageCallback.setIsInterstitial(this.mIsInterstitial);
    localImageCallback.setPrecache(paramBoolean);
    this.mLoadImageTask = new ImageFetchTask(this.mImageUrl, localImageCallback);
    this.mLoadImageTask.setCache(ImageCache.getInstance());
    Context localContext = getContext();
    this.mLoadImageTask.setScale(Utils.getScale(localContext));
    this.mLoadImageTask.execute(new Void[0]);
  }

  private View getAd(boolean paramBoolean)
  {
    if (!this.mIsInterstitial)
    {
      this.mImage = createImageView();
      downloadImage(paramBoolean);
      return wrapImageView(this.mImage);
    }
    downloadImage(paramBoolean);
    return null;
  }

  static void handleInterstitial(Bitmap paramBitmap, boolean paramBoolean, BurstlyImageAdaptor paramBurstlyImageAdaptor)
  {
    ImageView localImageView = paramBurstlyImageAdaptor.createImageView();
    localImageView.setImageBitmap(paramBitmap);
    handleInterstitial(paramBurstlyImageAdaptor.wrapImageView(localImageView), paramBoolean, paramBurstlyImageAdaptor);
  }

  static void handleInterstitial(View paramView, boolean paramBoolean, BurstlyImageAdaptor paramBurstlyImageAdaptor)
  {
    paramBurstlyImageAdaptor.mInterstitialView = paramView;
    paramBurstlyImageAdaptor.getAdaptorListener().didLoad("burstlyImage", true);
    if (!paramBoolean)
    {
      if (paramView != null)
      {
        paramView.setLayoutParams(new FrameLayout.LayoutParams(-2, -2, 17));
        AdaptorCustomFullscreen localAdaptorCustomFullscreen = new AdaptorCustomFullscreen(paramBurstlyImageAdaptor.getContext());
        localAdaptorCustomFullscreen.addView(paramView);
        if (paramBurstlyImageAdaptor.mIsTransparentBg)
          localAdaptorCustomFullscreen.setBackgroundColor(0);
        paramView.setFocusableInTouchMode(true);
        paramView.requestFocus();
        FullscreenOverlayContainer localFullscreenOverlayContainer = new FullscreenOverlayContainer(localAdaptorCustomFullscreen, "burstlyImage");
        Integer localInteger = paramBurstlyImageAdaptor.getResponseData().getSkipButtonActivationTime();
        if (localInteger != null)
          localFullscreenOverlayContainer.setCloseButtonActivationTimeout(1000 * localInteger.intValue());
        localFullscreenOverlayContainer.setRemoveOverlayedChildren(false);
        localFullscreenOverlayContainer.setInterstitialShowtime(paramBurstlyImageAdaptor.mInterstitialShowtime);
        localFullscreenOverlayContainer.setOverlayListener(paramBurstlyImageAdaptor);
        localFullscreenOverlayContainer.showOverlayed();
      }
    }
    else
      return;
    LOG.logError("burstlyImage", "View to show as custom interstitial is null. This could be cased by invalid success notification from ad network.", new Object[0]);
  }

  private ViewGroup wrapImageView(ImageView paramImageView)
  {
    paramImageView.setFocusable(true);
    ClickAwareWrapper localClickAwareWrapper = new ClickAwareWrapper(getContext(), getAdaptorListener(), getViewId(), "burstlyImage");
    localClickAwareWrapper.addView(paramImageView);
    return localClickAwareWrapper;
  }

  protected void checkParameters(Map<String, ?> paramMap)
    throws IllegalArgumentException
  {
    int i = 1;
    super.checkParameters(paramMap);
    this.mImageUrl = getResponseData().getImageUrl();
    Integer localInteger = getResponseData().getIsInterstital();
    int j;
    int k;
    if ((localInteger != null) && (localInteger.intValue() == i))
    {
      j = i;
      this.mIsInterstitial = j;
      Utils.checkNotNull(this.mImageUrl, "imageUrl can not be null");
      this.mInterstitialShowtime = getResponseData().getInterstitialShowtime();
      if (this.mInterstitialShowtime == null)
        this.mInterstitialShowtime = Integer.valueOf(15);
      ResponseBean.ResponseData.AdType localAdType = getResponseData().getAdType();
      if ((localAdType != null) && (localAdType.getExtendedProperty() != null))
      {
        if ((0x1000 & localAdType.getExtendedProperty().intValue()) == 0)
          break label154;
        k = i;
        label124: this.mIsTransparentBg = k;
      }
      if ((localInteger == null) || (localInteger.intValue() != i))
        break label160;
    }
    while (true)
    {
      this.mIsInterstitial = i;
      return;
      j = 0;
      break;
      label154: k = 0;
      break label124;
      label160: i = 0;
    }
  }

  ImageView createImageView()
  {
    ImageView localImageView = new ImageView(getContext());
    if (!this.mIsInterstitial)
      localImageView.setLayoutParams(getLayoutParamsResolver().resolveParameters());
    localImageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    localImageView.setOnTouchListener(new View.OnTouchListener()
    {
      public boolean onTouch(View paramAnonymousView, MotionEvent paramAnonymousMotionEvent)
      {
        switch (paramAnonymousMotionEvent.getAction())
        {
        default:
        case 0:
        }
        while (true)
        {
          return true;
          TranslateAnimation localTranslateAnimation = new TranslateAnimation(0.0F, 1.0F, 0.0F, 1.0F);
          localTranslateAnimation.setDuration(300L);
          paramAnonymousView.startAnimation(localTranslateAnimation);
        }
      }
    });
    return localImageView;
  }

  public void destroy()
  {
    super.destroy();
    this.mImage = null;
    this.mInterstitialView = null;
    sImageAdaptor = null;
    super.destroy();
  }

  protected View doGetNewAd()
  {
    return getAd(false);
  }

  public IBurstlyAdaptor.BurstlyAdType getAdType()
  {
    if (this.mIsInterstitial)
      return IBurstlyAdaptor.BurstlyAdType.INTERSTITIAL_AD_TYPE;
    return IBurstlyAdaptor.BurstlyAdType.BANNER_AD_TYPE;
  }

  public String getNetworkName()
  {
    return "burstlyImage";
  }

  public void onCloseOverlay()
  {
    getAdaptorListener().dismissedFullscreen(FULLSCREEN_INFO);
  }

  public void onShowOverlay()
  {
    getAdaptorListener().shownFullscreen(FULLSCREEN_INFO);
  }

  public View precacheAd()
  {
    return getAd(true);
  }

  public void precacheInterstitialAd()
  {
    downloadImage(true);
  }

  public void showPrecachedInterstitialAd()
  {
    handleInterstitial(this.mInterstitialView, false, this);
  }

  public void stop()
  {
    super.stop();
    if (this.mLoadImageTask != null)
      this.mLoadImageTask.cancel(true);
  }

  public boolean supports(String paramString)
  {
    return true;
  }

  private static final class ImageCallback extends DefaultRequestCallback<Bitmap>
  {
    private final Reference<BurstlyImageAdaptor> mAdaptor;
    private boolean mIsInterstitial;
    private boolean mIsPrecache;

    private ImageCallback(BurstlyImageAdaptor paramBurstlyImageAdaptor)
    {
      this.mAdaptor = new WeakReference(paramBurstlyImageAdaptor);
    }

    private void setIsInterstitial(boolean paramBoolean)
    {
      this.mIsInterstitial = paramBoolean;
    }

    private void setPrecache(boolean paramBoolean)
    {
      this.mIsPrecache = paramBoolean;
    }

    public void onFailUi(Bitmap paramBitmap)
    {
      BurstlyImageAdaptor localBurstlyImageAdaptor = (BurstlyImageAdaptor)this.mAdaptor.get();
      if ((localBurstlyImageAdaptor != null) && (!localBurstlyImageAdaptor.isStopped()))
      {
        BurstlyImageAdaptor.LOG.logError(localBurstlyImageAdaptor.mTag, "Image was not fetched. See log for details.", new Object[0]);
        localBurstlyImageAdaptor.getAdaptorListener().failedToLoad("burstlyImage", false, "");
      }
    }

    public void onSuccessUi(Bitmap paramBitmap)
    {
      BurstlyImageAdaptor localBurstlyImageAdaptor = (BurstlyImageAdaptor)this.mAdaptor.get();
      if ((localBurstlyImageAdaptor != null) && (!localBurstlyImageAdaptor.isStopped()))
      {
        if (!this.mIsInterstitial)
        {
          ImageView localImageView = localBurstlyImageAdaptor.mImage;
          localImageView.setAdjustViewBounds(true);
          localImageView.setImageBitmap(paramBitmap);
          localBurstlyImageAdaptor.getAdaptorListener().didLoad("burstlyImage", this.mIsInterstitial);
          BurstlyImageAdaptor.LOG.logInfo(localBurstlyImageAdaptor.mTag, "Image fetched by url came from burstly.", new Object[0]);
        }
      }
      else
        return;
      BurstlyImageAdaptor.handleInterstitial(paramBitmap, this.mIsPrecache, localBurstlyImageAdaptor);
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.BurstlyImageAdaptor
 * JD-Core Version:    0.6.2
 */